package short_semester.questionnaire_planet.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.NoArgsConstructor;
import short_semester.questionnaire_planet.request.editRequest.EditScoreQuestionBody;

import javax.persistence.*;
import java.util.LinkedList;
import java.util.List;

@Entity
@Table
@Data
@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
@NoArgsConstructor
public class ScoreQuestion {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
    private Questionnaire questionnaire;


    @Column
    private String title = "";

    @Column     //描述
    private String description = "";

    // 是否必答
    @Column
    private Boolean isNecessary = true;

    @JsonIgnore
    @Column
    private Integer sequence;

    @Column
    private Integer count = 0;
    //子类型
    private String qtype = null;
    @Transient
    private String type = "score";

    //关联逻辑
    private String logic = "且";

    private String relationString;
    @Transient
    private Boolean isShow = true;

    @Transient
    private List<ScoreOption> options = new LinkedList<>();
    
    public void setValueFrom(EditScoreQuestionBody body){
        title = body.getTitle();
        description = body.getDescription();
        isNecessary = body.getIsNecessary();

    }
    
    public ScoreQuestion(ScoreQuestion question){
        title = question.getTitle();
        description = question.getDescription();
        isNecessary = question.getIsNecessary();
        sequence = question.getSequence();
        qtype=question.getQtype();

    }

    public ScoreQuestion(String qtype) {
        this.qtype = qtype;
    }
}
